/* Check JER_Make_Decoding_Matrix(). 
   reed_sol... already checked. */
#include <stdio.h>
#include "jerasure.h"
#include "reed_sol.h"

int main( int argc, char** argv )
{
	int *old_matrix;
	int *bitmatrix;
	int *inverse_matrix;
	int i, j, tmp;
	int m = atoi( argv[1] );
	int k = atoi( argv[2] );
	int w = atoi( argv[3] );
	int *erased, *dm_ids;

	erased = (int*) calloc( k + m, sizeof(int) );
	dm_ids = (int*) malloc( ( k + m ) * sizeof( int ) );
	
	inverse_matrix = (int*) malloc( sizeof(int) * k * k );
	old_matrix = reed_sol_vandermonde_coding_matrix( k, m, w );
	srand48(m);
	for( i = 0; i < m; i++ )
	{
		tmp = lrand48() % ( k + m );
		if( erased[tmp] == 1 )
			i--;
		erased[tmp] = 1;
	}

	for( i = 0; i < k+m; i++ )
		if( erased[i] == 0 )
			fprintf( stdout, "Drive %d survived\n", i );

	jerasure_make_decoding_matrix( k, m, w, old_matrix, erased, 
			inverse_matrix, dm_ids );
		
	if( inverse_matrix != NULL )
		jerasure_print_matrix( inverse_matrix, k, k, w );

	return 0;
}
